package cn.edu.zjut.advice;


import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;
import java.util.Date;

/**
 * @author XiaoFeng
 * @version 1.0
 * @Description 创 建 Around 类 型 的 增 强 处 理LoggingInterceptor.java，并在其 invoke 方法中定义日志管理功能
 * Create by 2021/12/6 21:11
 */

public class LoggingInterceptor implements MethodInterceptor {

    public Object invoke(MethodInvocation invocation) throws Throwable {
        Object[] args = invocation.getArguments();
        String date1 = (new Date()).toString();
        System.out.println("Interceptor 信息：[logging before ][" + date1 + "]用户 " + args[0] + " 尝试修改个人信息...");
        Object returnObject = invocation.proceed();
        String date2 = (new Date()).toString();
        System.out.println("Interceptor 信息：[logging after ][" + date2 + "]用户 " + args[0] + " 成功修改个人信息...");
        return args;
    }
}
